package com.jml.mybatis.demo;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MybatisUtils {
	private final static SqlSessionFactory sqlSessionFactory ;
	static {
		//这个配置文件要把它放在源码包下，并且编译后要看clazz文件是否有这个配置文件。否则报错文件找不到
		String resource = "mybatis-config.xml";
		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
	}
	public static  SqlSessionFactory  getSqlSessionFactory(){
		return sqlSessionFactory;
	}

}
